package request

import (
	"github.com/astaxie/beego/validation"
	"shop-common/utils"
	"shop-common/utils/pagehelper"
)

type SysXhrRequest struct {
	Id       uint   `json:"id"`                                    //主键
	FullPath string `json:"fullPath" binding:"required"`           //请求路径
	Method   string `json:"method" binding:"required"`             //方法
	Category string `json:"category" binding:"required"`           //分组
	Describe string `json:"describe"`                              //简介
	Status   int    `json:"status" binding:"required" default:"2"` //状态  1:停用   2:启用
}

func (s *SysXhrRequest) Valid(v *validation.Validation) {
	if s.FullPath == "" {
		v.SetError("FullPath", "请求路径不能为空")
	} else if s.Method == "" {
		v.SetError("Method", "请求方法不能为空")
	} else if s.Category == "" {
		v.SetError("Category", "分组不能为空")
	} else if !utils.IntIncludes([]int{1, 2}, s.Status) {
		v.SetError("Status", "状态不合法")
	}
}

type SysXhrSearchRequest struct {
	pagehelper.SearchPageRequest
	Category string `json:"category"`
	Method   string `json:"method"`
}

type UpdateSysXhrStatusRequest struct {
	Id     uint `json:"id" binding:"required"`
	Status int  `json:"status" binding:"required" default:"2"` //状态  1：停用   2：启用
}

func (s *UpdateSysXhrStatusRequest) Valid(v *validation.Validation) {
	if s.Id <= 0 {
		v.SetError("Id", "Id不合法")
	} else if !utils.IntIncludes([]int{1, 2}, s.Status) {
		v.SetError("Status", "状态不合法")
	}
}
